// pages/check/management/management.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		index: 0,
		state: false,
	},
	onShow: function(options) {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid,
				})
				this.tj()
			}
		})
	},
	tj() {
		wx.request({
			url: getApp().globalData.chang + 'action=getServerList&uid=' + this.data.uid,
			success: (res) => {
				console.log(res)
				this.setData({
					data: res.data.data,
					state: false,
				})
			}
		})
	},
	state(e) {
		this.setData({
			state: true,
			index1: e.currentTarget.dataset.index
		})
	},
	none(e) {
		this.setData({
			state: false
		})
	},
	putaway(e) {
		if (e.currentTarget.dataset.sta != 2) {
			wx.request({
				url: getApp().globalData.chang + 'action=pushServer&id=' + e.currentTarget.dataset.id,
				success: (e) => {
					console.log(e)
					this.setData({
						state: false,
						data:[],
					})
					this.tj()
				}
			})
		} else {
			wx.showToast({
				icon: 'none',
				title: '该商品已上架'
			})
		}
	},
	sold(e) {
		wx.request({
			url: getApp().globalData.chang + 'action=downServer&id=' + e.currentTarget.dataset.id,
			success: (e) => {
				this.setData({
					state: false,
					data:[],
				})
				this.tj()
			}
		})
	},
	cancel(e){
		wx.request({
			url:getApp().globalData.chang+'action=delServer&id='+ e.currentTarget.dataset.id+'&uid='+this.data.uid,
			success: (e) => {
				this.setData({
					state: false,
					data:[],
				})
				this.tj()
			}
		})
	}
})
